import glob
import logging
import os
from pathlib import Path
from 获取数据 import get_data
import concurrent.futures
from datetime import datetime, timedelta
from dingding import SendFile
from login import login

# 账号
usernames1 = {'username': 'yexiong1997@qq.com', 'password': 'Yexiong1997', 'port': 9225, 'user_path': r"C:\15867710780",
              'down_path': r"C:\15867710780\filedownloads"}
usernames2 = {'username': '594688317@qq.com', 'password': 'Yh5566789', 'port': 9223, 'user_path': r"C:\594688317",
              'down_path': r"C:\594688317\filedownloads"}
usernames3 = {'username': '791002765@qq.com', 'password': 'yexiong1997Mm', 'port': 9224, 'user_path': r"C:\791002765",
              'down_path': r"C:\791002765\filedownloads"}
usernames4 = {'username': '2968425169@qq.com', 'password': 'yexiong1997Mm', 'port': 9226, 'user_path': r"C:\2968425169",
              'down_path': r"C:\2968425169\filedownloads"}
usernames5 = {'username': 'yexiong1108@qq.com', 'password': 'yexiong1997Mm', 'port': 9240,
              'user_path': r"C:\yexiong1108", 'down_path': r"C:\yexiong1108\filedownloads"}
usernames6 = {'username': 'y2968425169@foxmail.com', 'password': 'Yexiong1997', 'port': 9241,
              'user_path': r"C:\y2968425169", 'down_path': r"C:\y2968425169\filedownloads"}
usernames7 = {'username': 'yexiong1997@163.com', 'password': 'yexiong1997Mm', 'port': 9242,
              'user_path': r"C:\yexiong1997", 'down_path': r"C:\yexiong1997\filedownloads"}

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    date = (datetime.now()-timedelta(days=1)).strftime("%Y-%m-%d")
    # date = '2024-04-01-2024-04-30'
    Path(f'C:/抖音店铺违规积分/{date}').mkdir(parents=True, exist_ok=True)
    # 检查是否登录
    login(usernames1)
    login(usernames2)
    login(usernames3)
    login(usernames4)
    login(usernames5)
    login(usernames6)
    login(usernames7)
    # 创建线程池
    with concurrent.futures.ThreadPoolExecutor() as executor:
        # 提交任务到线程池
        future1 = executor.submit(get_data, usernames1['port'], usernames1['user_path'], usernames1['down_path'],
                                  date, usernames1)
        future2 = executor.submit(get_data, usernames2['port'], usernames2['user_path'], usernames2['down_path'],
                                  date, usernames2)
        future3 = executor.submit(get_data, usernames3['port'], usernames3['user_path'], usernames3['down_path'],
                                  date, usernames3)
        future4 = executor.submit(get_data, usernames4['port'], usernames4['user_path'], usernames4['down_path'],
                                  date, usernames4)
        future5 = executor.submit(get_data, usernames5['port'], usernames5['user_path'], usernames5['down_path'],
                                  date, usernames5)
        future6 = executor.submit(get_data, usernames6['port'], usernames6['user_path'], usernames6['down_path'],
                                  date, usernames6)
        future7 = executor.submit(get_data, usernames7['port'], usernames7['user_path'], usernames7['down_path'],
                                  date, usernames7)
        # concurrent.futures.wait([future5])
        concurrent.futures.wait([future1, future2, future3, future4, future5, future6, future7])
        # 获取函数的返回值
        result1 = future1.result()
        result2 = future2.result()
        result3 = future3.result()
        result4 = future4.result()
        result5 = future5.result()
        result6 = future6.result()
        result7 = future7.result()
        # print(result5)
        print(result1, result2, result3, result4, result5, result6, result7)
    if result1 == '成功' and result2 == '成功' and result3 == '成功' and result4 == '成功' and result5 == '成功' and result6 == '成功' and result7 == '成功':
        print('全部成功')
    else:
        raise Exception('有店铺数据未获取成功，请检查')
